<%@ page import="com.ray.pojo.User" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">

<body>

<a href="${pageContext.request.contextPath}/viewUser" class="btn btn-primary" role="button">新增</a>

<h2>用户列表(使用jsp书写)</h2>

<table class="table table-striped">
    <thead>
    <tr>
        <th scope="col">编号</th>
        <th scope="col">姓名</th>
        <th scope="col">性别</th>
        <th scope="col">操作</th>
    </tr>
    </thead>
    <tbody>

    <%
        List<User> alluser = (List<User>) request.getAttribute("alluser");
        for (User user : alluser)
        {
    %>

    <tr>
        <td><%= user.getId()%></td>
        <td><%= user.getName()%></td>
        <td>

            <span>
                <% if (user.getGender() == 0){ %>
                    男
                <% }else {%>
                女
                <%}%>
            </span>

        </td>
        <td>
            <a class="btn btn-outline-primary" href="${pageContext.request.contextPath}/viewUser?userid=<%= user.getId()%>" role="button">修改</a>
            <a class="btn btn-outline-danger" href="${pageContext.request.contextPath}/deleteUser?userid=<%= user.getId()%>" role="button">删除</a>
        </td>
    </tr>
    <%  } %>
    </tbody>
</table>


<h2>用户列表(使用jstl书写)</h2>

<table class="table table-striped">
    <thead>
    <tr>
        <th scope="col">编号</th>
        <th scope="col">姓名</th>
        <th scope="col">性别</th>
        <th scope="col">操作</th>

    </tr>
    </thead>
    <tbody>
    <c:forEach var="user" items="${alluser}" varStatus="status">
    <tr>
        <td>${user.getId()}</td>
        <td>${user.getName()}</td>
        <td>
            <c:if test="${user.getGender()==0}">男</c:if>
            <c:if test="${user.getGender()==1}">女</c:if>
        </td>
        <td>
            <a class="btn btn-outline-primary" href="${pageContext.request.contextPath}/viewUser?userid=${user.getId()}" role="button">修改</a>
            <a class="btn btn-outline-danger" href="${pageContext.request.contextPath}/deleteUser?userid=${user.getId()}" role="button">删除</a>
        </td>
    </tr>
    </c:forEach>
    </tbody>
</table>
</body>
</html>
